package com.mars.admin.modules.sys.controller;

import java.util.Arrays;
import java.util.Map;

import com.mars.admin.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.mars.admin.modules.sys.entity.SensorNeedfixEntity;
import com.mars.admin.modules.sys.service.SensorNeedfixService;
import com.mars.admin.common.utils.PageUtils;
import com.mars.admin.common.utils.R;



/**
 * 分配需要维修的传感器
 *
 * @author lrj
 * @email lrjchina88@gmail.com
 * @date 2018-08-10 09:21:20
 */
@RestController
@RequestMapping("sys/sensorneedfix")
public class SensorNeedfixController {
    @Autowired
    private SensorNeedfixService sensorNeedfixService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:sensorneedfix:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = sensorNeedfixService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:sensorneedfix:info")
    public R info(@PathVariable("id") Integer id){
        SensorNeedfixEntity sensorNeedfix = sensorNeedfixService.selectById(id);

        return R.ok().put("sensorNeedfix", sensorNeedfix);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:sensorneedfix:save")
    public R save(@RequestBody SensorNeedfixEntity sensorNeedfix){
        sensorNeedfixService.insert(sensorNeedfix);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:sensorneedfix:update")
    public R update(@RequestBody SensorNeedfixEntity sensorNeedfix){
        ValidatorUtils.validateEntity(sensorNeedfix);
        sensorNeedfixService.updateAllColumnById(sensorNeedfix);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:sensorneedfix:delete")
    public R delete(@RequestBody Integer[] ids){
        sensorNeedfixService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

}
